﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Psm.PubSub.Configuration;

namespace Psm.PubSub.StateCache
{
    internal class StateCache
    {
        public static StateCache Instance { get; private set; }

        static StateCache()
        {
            Instance = new StateCache();
        }

        private Dictionary<string, TopicSpace> topics = new Dictionary<string, TopicSpace>();

        public StateCache()
        {
            foreach (Schema schema in SchemaCollection.AllSchemas.Values)
            {
                topics.Add(schema.Topic, new TopicSpace( schema ) );
            }
        }

        public TopicSpace GetTopicSpace(string topic)
        {
            return this.topics[topic];
        }

        public TopicSpace[] GetAllSpaces()
        {
            return this.topics.Values.ToArray();
        }
    }
}
